package com.ourteam.system.dao.impl;

import com.ourteam.system.dao.ISysAllRoleDAO;
import com.ourteam.system.dao.SysAllRole;
import com.ourteam.system.dao.SysAllRoleDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-07-31 15:13:38
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractSysAllRoleDAOJdbcImpl extends AbstractSpringDAO
    implements ISysAllRoleDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, DomainId, RoleCode, RoleName, RoleType, Status, Remarks,
            DomainCode, DomainName
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.DomainId,
            _DataObjectProperty.RoleCode, _DataObjectProperty.RoleName,
            _DataObjectProperty.RoleType, _DataObjectProperty.Status,
            _DataObjectProperty.Remarks, _DataObjectProperty.DomainCode,
            _DataObjectProperty.DomainName
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<SysAllRole, SysAllRoleDAOQueryBean> daoHelper;

    public AbstractSysAllRoleDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<SysAllRole, SysAllRoleDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysDomainDAO.EntityName)
                                .append(" SYS_DOMAIN ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysDomainDAO.Id,
                    com.ourteam.system.dao.ISysDomainDAO.EntityName + ".",
                    "SYS_DOMAIN."));
            relatedJoinSQLBuffer.append(" = ").append(DomainId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aSysAllRole
         * @throws Exception
         */
    public boolean checkIsUnique(SysAllRole aSysAllRole)
        throws Exception {
        if (aSysAllRole == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aSysAllRole.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aSysAllRole
     * @throws Exception
     */
    public void insert(SysAllRole aSysAllRole) throws Exception {
        super.doInsert(aSysAllRole);
    }

    /**
         * Batch Insert Datas
         * @param aSysAllRole
         * @throws Exception
         */
    public void batchInsert(SysAllRole[] aSysAllRoles)
        throws Exception {
        super.doBatchInsert(aSysAllRoles);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(SysAllRoleDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(SysAllRole aSysAllRole) throws Exception {
        delete(aSysAllRole.getId());
    }

    /**
     * Update Data Selective
     * @param aSysAllRole
     * @throws Exception
     */
    public void update(SysAllRole aSysAllRole) throws Exception {
        if (aSysAllRole.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aSysAllRole);

        SysAllRole tempObj = findById(aSysAllRole.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aSysAllRole, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aSysAllRoles[]
     * @throws Exception
     */
    public void batchUpdate(SysAllRole[] aSysAllRoles)
        throws Exception {
        super.doBatchUpdate(aSysAllRoles);
    }

    /**
         * Update Data By Condictions
         * @param aSysAllRole
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(SysAllRole aSysAllRole, SysAllRoleDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aSysAllRole, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(SysAllRoleDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(SysAllRole aSysAllRole)
        throws Exception {
        if (aSysAllRole.getRoleCode() == null) {
            throw new Exception(
                "The SysAllRole.roleCode value is not allow NULL");
        }

        if (aSysAllRole.getRoleName() == null) {
            throw new Exception(
                "The SysAllRole.roleName value is not allow NULL");
        }

        if (aSysAllRole.getRoleType() == null) {
            throw new Exception(
                "The SysAllRole.roleType value is not allow NULL");
        }

        if (aSysAllRole.getStatus() == null) {
            throw new Exception("The SysAllRole.status value is not allow NULL");
        }

        if (aSysAllRole.getRemarks() == null) {
            throw new Exception(
                "The SysAllRole.remarks value is not allow NULL");
        }

        if (aSysAllRole.getDomainCode() == null) {
            throw new Exception(
                "The SysAllRole.domainCode value is not allow NULL");
        }

        if (aSysAllRole.getDomainName() == null) {
            throw new Exception(
                "The SysAllRole.domainName value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public SysAllRole findById(final long id) throws Exception {
        SysAllRoleDAOQueryBean queryBean = new SysAllRoleDAOQueryBean();

        SysAllRoleDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        SysAllRole[] SysAllRoles = query(queryBean);

        if (SysAllRoles.length == 0) {
            return null;
        } else {
            return SysAllRoles[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return SysAllRole[]
         * @throws Exception
         */
    public SysAllRole[] query(SysAllRoleDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean, new JdbcSysAllRoleRowMapper());

        return (SysAllRole[]) result.toArray(new SysAllRole[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        SysAllRoleDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(SysAllRoleDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(SysAllRole[] aSysAllRoles,
        SysAllRoleDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aSysAllRoles, queryBean);
    }

    public void synchronize(SysAllRole[] aSysAllRoles,
        SysAllRoleDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<SysAllRole> callBack)
        throws Exception {
        daoHelper.synchronize(aSysAllRoles, queryBean, callBack);
    }

    public static class JdbcSysAllRoleRowMapper implements RowMapper<SysAllRole> {
        public SysAllRole mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            SysAllRole object = new SysAllRole();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object domainId = null;

                domainId = resultSet.getObject(columnIndex++);

                object.setDomainIdNull(resultSet.getBoolean(columnIndex++));

                if (domainId != null) {
                    setBeanValue(object, _DataObjectProperty.DomainId, domainId);
                }

                Object roleCode = null;

                roleCode = resultSet.getObject(columnIndex++);

                object.setRoleCodeNull(resultSet.getBoolean(columnIndex++));

                if (roleCode != null) {
                    setBeanValue(object, _DataObjectProperty.RoleCode, roleCode);
                }

                Object roleName = null;

                roleName = resultSet.getObject(columnIndex++);

                object.setRoleNameNull(resultSet.getBoolean(columnIndex++));

                if (roleName != null) {
                    setBeanValue(object, _DataObjectProperty.RoleName, roleName);
                }

                Object roleType = null;

                roleType = resultSet.getObject(columnIndex++);

                object.setRoleTypeNull(resultSet.getBoolean(columnIndex++));

                if (roleType != null) {
                    setBeanValue(object, _DataObjectProperty.RoleType, roleType);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object domainCode = null;

                domainCode = resultSet.getObject(columnIndex++);

                object.setDomainCodeNull(resultSet.getBoolean(columnIndex++));

                if (domainCode != null) {
                    setBeanValue(object, _DataObjectProperty.DomainCode,
                        domainCode);
                }

                Object domainName = null;

                domainName = resultSet.getObject(columnIndex++);

                object.setDomainNameNull(resultSet.getBoolean(columnIndex++));

                if (domainName != null) {
                    setBeanValue(object, _DataObjectProperty.DomainName,
                        domainName);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
